/*
 *  Copyright 2011-2012 Redia A/S
 * 
 *  This file is part of Redias Android Utilities.
 *
 *  Redias Android Utilities is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Redias Android Utilities is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with Redias Android Utilities.  If not, see <http://www.gnu.org/licenses/>.
 */
package dk.redia.lib.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Display;
import android.view.WindowManager;

public class UIUtils {
	
	private static int screenWidth = -1;
	private static int screenHeight = -1;
	
	public static int dipToPx(int dpi) {
		return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpi, AppApplication.getAppContext().getResources().getDisplayMetrics());
	}
	
	public static int pxToDip(int px) {
		DisplayMetrics metrics = AppApplication.getAppContext().getResources().getDisplayMetrics();
		return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, px, metrics);
	}
	
	public static int getScreenWidth() {
		if (screenWidth<0) {
			Display display = ((WindowManager) AppApplication.getAppContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
			screenWidth = display.getWidth();
		}
		return screenWidth;
	}
	
	public static int getScreenHeight() {
		if (screenHeight<0) {
			Display display = ((WindowManager) AppApplication.getAppContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
			screenHeight = display.getWidth();
		}
		return screenHeight;
	}
}
